package com.huishou.lajiMain.config.zhujie;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/*
 * @Author:大力王
 * @Date:2024/5/11-11-3:03
 * 开始了
 */
@Aspect
@Component
public class LoggingAspect {
    private static final Logger logger = LoggerFactory.getLogger(LoggingAspect.class);

    @Around("@annotation(LogginInfo)")
    public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
        long start = System.currentTimeMillis();

        // 在方法执行前记录日志
        logger.info("开始执行: " + joinPoint.toString());

        try {
            return joinPoint.proceed();
        } finally {
            // 在方法执行后记录日志
            long executionTime = System.currentTimeMillis() - start;
            logger.info("完成执行: " + joinPoint.getSignature() + ", 用时: " + executionTime + "ms");
        }
    }
    @Around("@annotation(LoginStr)")
    public Object logInfo(ProceedingJoinPoint pjp, LoginStr LoginStr) throws Throwable {
        // 在方法执行前进行操作，如记录日志
        logger.info("Before method execution");

        // 执行目标方法并获取结果
        Object result = pjp.proceed();
        logger.info(LoginStr.value()+":");
        // 在方法执行后进行操作，如记录日志
        logger.info("After method execution");

        return result;
    }
}
